package src.com.qf.dao.impl;


import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import src.com.qf.dao.OrderDetailDao;
import src.com.qf.entity.OrderDetail;
import src.com.qf.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

public class OrderDetailDaoImpl implements OrderDetailDao {
    private QueryRunner queryRunner = new QueryRunner();
    @Override
    public void insertOrderDetail(OrderDetail od) {
        String sql = "insert into tb_orderDetail(oid,gid,num,sum) values(?,?,?,?)";
        try {
            queryRunner.update(JdbcUtil.getCon(),sql,od.getOid(),od.getGid(),od.getNum(),od.getSum());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<OrderDetail> selectOrderDetailsByOid(Integer id) {
        String sql = "select *from tb_orderDetail where oid=?";
        List<OrderDetail> query = null;
        try {
            query = queryRunner.query(JdbcUtil.getCon(),sql,new BeanListHandler<>(OrderDetail.class),id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }
}
